package com.greate.community.controller.Background;

import com.greate.community.common.Result;
import com.greate.community.entity.UserInfo;
import com.greate.community.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:xiaohai 2072158919@qq.com 海航源
 * @Date: 2025/4/16  下午6:44
 * @Version 1.0
 * @description
 */
@RestController
@RequestMapping("/api/manage")
@CrossOrigin(origins = "http://localhost:5666")
public class BackgroundManageController {

    @Autowired
    private UserInfoService userInfoService;

    @GetMapping("/info")
    public Result<Object> getManageInfo() {
        UserInfo userInfo = userInfoService.getUserInfo();
        if (userInfo == null) {
            return Result.error("获取统计信息失败");
        }
        
        Map<String, Object> data = new HashMap<>();
        
        // 用户量数据
        Map<String, Object> userCount = new HashMap<>();
        userCount.put("current", userInfo.getCurrentUserCount());
        userCount.put("total", userInfo.getTotalUserCount());
        data.put("userCount", userCount);
        
        // 访问量数据
        Map<String, Object> visitCount = new HashMap<>();
        visitCount.put("current", userInfo.getCurrentVisitCount());
        visitCount.put("total", userInfo.getTotalVisitCount());
        data.put("visitCount", visitCount);
        
        // 下载量数据
        Map<String, Object> downloadCount = new HashMap<>();
        downloadCount.put("current", userInfo.getCurrentDownloadCount());
        downloadCount.put("total", userInfo.getTotalDownloadCount());
        data.put("downloadCount", downloadCount);
        
        // 使用量数据
        Map<String, Object> usageCount = new HashMap<>();
        usageCount.put("current", userInfo.getCurrentUsageCount());
        usageCount.put("total", userInfo.getTotalUsageCount());
        data.put("usageCount", usageCount);
        
        return Result.success(data);
    }

}
